using System;
using EPiServer.Common;
using EPiServer.Common.Queries;
using EPiServer.Common.Security;
using EPiServer.Community.Contest;
using EPiServer.Community.Contest.Queries;

namespace EPiAbstractions.Community.Contest
{
    public class ContestHandlerFacade : IContestHandlerFacade
    {
        private static ContestHandlerFacade _instance;

        public ContestHandlerFacade()
        {
            ContestHandler.ContestAdded += OnContestAdded;
            ContestHandler.ContestUpdated += OnContestUpdated;
            ContestHandler.ContestRemoved += OnContestRemoved;
            ContestHandler.QuestionAdded += OnQuestionAdded;
            ContestHandler.QuestionUpdated += OnQuestionUpdated;
            ContestHandler.QuestionRemoved += OnQuestionRemoved;
            ContestHandler.AlternativeAdded += OnAlternativeAdded;
            ContestHandler.AlternativeUpdated += OnAlternativeUpdated;
            ContestHandler.AlternativeRemoved += OnAlternativeRemoved;
            ContestHandler.AnswerAdded += OnAnswerAdded;
            ContestHandler.SubmissionAdded += OnSubmissionAdded;
            ContestHandler.SubmissionRemoved += OnSubmissionRemoved;
            ContestHandler.WinnerAdded += OnWinnerAdded;
            ContestHandler.WinnerRemoved += OnWinnerRemoved;
        }

        public static ContestHandlerFacade Instance
        {
            get
            {
                if (_instance == null)
                    _instance = new ContestHandlerFacade();

                return _instance;
            }

            set { _instance = value; }
        }

        #region IContestHandlerFacade Members

        public event EPiServerCommonEventHandler ContestAdded;
        public event EPiServerCommonEventHandler ContestUpdated;
        public event EPiServerCommonEventHandler ContestRemoved;
        public event EPiServerCommonEventHandler QuestionAdded;
        public event EPiServerCommonEventHandler QuestionUpdated;
        public event EPiServerCommonEventHandler QuestionRemoved;
        public event EPiServerCommonEventHandler AlternativeAdded;
        public event EPiServerCommonEventHandler AlternativeUpdated;
        public event EPiServerCommonEventHandler AlternativeRemoved;
        public event EPiServerCommonEventHandler AnswerAdded;
        public event EPiServerCommonEventHandler SubmissionAdded;
        public event EPiServerCommonEventHandler SubmissionRemoved;
        public event EPiServerCommonEventHandler WinnerAdded;
        public event EPiServerCommonEventHandler WinnerRemoved;

        public virtual EPiServer.Community.Contest.Contest GetContest(Int32 id)
        {
            return ContestHandler.GetContest(id);
        }

        public virtual EPiServer.Community.Contest.Contest AddContest(EPiServer.Community.Contest.Contest contest)
        {
            return ContestHandler.AddContest(contest);
        }

        public virtual void RemoveContest(EPiServer.Community.Contest.Contest contest)
        {
            ContestHandler.RemoveContest(contest);
        }

        public virtual void UpdateContest(EPiServer.Community.Contest.Contest contest)
        {
            ContestHandler.UpdateContest(contest);
        }

        public virtual ContestCollection GetContests(Int32 page, Int32 pageSize, ContestSortOrder[] sortOrder)
        {
            return ContestHandler.GetContests(page, pageSize, sortOrder);
        }

        public virtual ContestCollection GetContests(Int32 page, Int32 pageSize, out Int32 totalItems, ContestSortOrder[] sortOrder)
        {
            return ContestHandler.GetContests(page, pageSize, out totalItems, sortOrder);
        }

        public virtual ContestCollection GetContests(Int32 page, Int32 pageSize, SiteCollection sites, ContestSortOrder[] sortOrder)
        {
            return ContestHandler.GetContests(page, pageSize, sites, sortOrder);
        }

        public virtual ContestCollection GetContests(Int32 page, Int32 pageSize, SiteCollection sites, out Int32 totalItems,
                                                     ContestSortOrder[] sortOrder)
        {
            return ContestHandler.GetContests(page, pageSize, sites, out totalItems, sortOrder);
        }

        public virtual ContestCollection GetContests(Int32 page, Int32 pageSize, SiteCollection sites, NullValueAction siteNullAction,
                                                     ContestSortOrder[] sortOrder)
        {
            return ContestHandler.GetContests(page, pageSize, sites, siteNullAction, sortOrder);
        }

        public virtual ContestCollection GetContests(Int32 page, Int32 pageSize, SiteCollection sites, NullValueAction siteNullAction,
                                                     out Int32 totalItems, ContestSortOrder[] sortOrder)
        {
            return ContestHandler.GetContests(page, pageSize, sites, siteNullAction, out totalItems, sortOrder);
        }

        public virtual Question GetQuestion(Int32 id)
        {
            return ContestHandler.GetQuestion(id);
        }

        public virtual SubmissionCollection GetSubmissions(EPiServer.Community.Contest.Contest contest, Int32 page, Int32 pageSize)
        {
            return ContestHandler.GetSubmissions(contest, page, pageSize);
        }

        public virtual SubmissionCollection GetSubmissions(EPiServer.Community.Contest.Contest contest, Int32 page, Int32 pageSize,
                                                           out Int32 totalItems)
        {
            return ContestHandler.GetSubmissions(contest, page, pageSize, out totalItems);
        }

        public virtual SubmissionCollection GetSubmissions(EPiServer.Community.Contest.Contest contest, Int32 page, Int32 pageSize,
                                                           SubmissionSortOrder[] sortOrder)
        {
            return ContestHandler.GetSubmissions(contest, page, pageSize, sortOrder);
        }

        public virtual SubmissionCollection GetSubmissions(EPiServer.Community.Contest.Contest contest, Int32 page, Int32 pageSize,
                                                           out Int32 totalItems, SubmissionSortOrder[] sortOrder)
        {
            return ContestHandler.GetSubmissions(contest, page, pageSize, out totalItems, sortOrder);
        }

        public virtual Submission AddSubmission(Submission submission)
        {
            return ContestHandler.AddSubmission(submission);
        }

        public virtual Submission GetSubmission(Int32 id)
        {
            return ContestHandler.GetSubmission(id);
        }

        public virtual Submission GetSubmission(IUser user, EPiServer.Community.Contest.Contest contest)
        {
            return ContestHandler.GetSubmission(user, contest);
        }

        public virtual void RemoveSubmission(Submission submission)
        {
            ContestHandler.RemoveSubmission(submission);
        }

        public virtual Alternative GetAlternative(Int32 id)
        {
            return ContestHandler.GetAlternative(id);
        }

        public virtual Answer GetAnswer(Int32 id)
        {
            return ContestHandler.GetAnswer(id);
        }

        public virtual ContestCollection GetQueryResult(ContestQuery query)
        {
            return ContestHandler.GetQueryResult(query);
        }

        public virtual ContestCollection GetQueryResult(ContestQuery query, Int32 page, Int32 pageSize)
        {
            return ContestHandler.GetQueryResult(query, page, pageSize);
        }

        public virtual ContestCollection GetQueryResult(ContestQuery query, Int32 page, Int32 pageSize, out Int32 totalItems)
        {
            return ContestHandler.GetQueryResult(query, page, pageSize, out totalItems);
        }

        public virtual AnswerCollection GetQueryResult(AnswerQuery query)
        {
            return ContestHandler.GetQueryResult(query);
        }

        public virtual AnswerCollection GetQueryResult(AnswerQuery query, Int32 page, Int32 pageSize)
        {
            return ContestHandler.GetQueryResult(query, page, pageSize);
        }

        public virtual AnswerCollection GetQueryResult(AnswerQuery query, Int32 page, Int32 pageSize, out Int32 totalItems)
        {
            return ContestHandler.GetQueryResult(query, page, pageSize, out totalItems);
        }

        public virtual AnswerCollection GetQueryResult(TextAnswerQuery query)
        {
            return ContestHandler.GetQueryResult(query);
        }

        public virtual AnswerCollection GetQueryResult(TextAnswerQuery query, Int32 page, Int32 pageSize)
        {
            return ContestHandler.GetQueryResult(query, page, pageSize);
        }

        public virtual AnswerCollection GetQueryResult(TextAnswerQuery query, Int32 page, Int32 pageSize, out Int32 totalItems)
        {
            return ContestHandler.GetQueryResult(query, page, pageSize, out totalItems);
        }

        public virtual AnswerCollection GetQueryResult(SingleAlternativeAnswerQuery query)
        {
            return ContestHandler.GetQueryResult(query);
        }

        public virtual AnswerCollection GetQueryResult(SingleAlternativeAnswerQuery query, Int32 page, Int32 pageSize)
        {
            return ContestHandler.GetQueryResult(query, page, pageSize);
        }

        public virtual AnswerCollection GetQueryResult(SingleAlternativeAnswerQuery query, Int32 page, Int32 pageSize, out Int32 totalItems)
        {
            return ContestHandler.GetQueryResult(query, page, pageSize, out totalItems);
        }

        public virtual AnswerCollection GetQueryResult(MultipleAlternativeAnswerQuery query)
        {
            return ContestHandler.GetQueryResult(query);
        }

        public virtual AnswerCollection GetQueryResult(MultipleAlternativeAnswerQuery query, Int32 page, Int32 pageSize)
        {
            return ContestHandler.GetQueryResult(query, page, pageSize);
        }

        public virtual AnswerCollection GetQueryResult(MultipleAlternativeAnswerQuery query, Int32 page, Int32 pageSize,
                                                       out Int32 totalItems)
        {
            return ContestHandler.GetQueryResult(query, page, pageSize, out totalItems);
        }

        public virtual QuestionCollection GetQueryResult(QuestionQuery query)
        {
            return ContestHandler.GetQueryResult(query);
        }

        public virtual QuestionCollection GetQueryResult(QuestionQuery query, Int32 page, Int32 pageSize)
        {
            return ContestHandler.GetQueryResult(query, page, pageSize);
        }

        public virtual QuestionCollection GetQueryResult(QuestionQuery query, Int32 page, Int32 pageSize, out Int32 totalItems)
        {
            return ContestHandler.GetQueryResult(query, page, pageSize, out totalItems);
        }

        public virtual SubmissionCollection GetQueryResult(SubmissionQuery query)
        {
            return ContestHandler.GetQueryResult(query);
        }

        public virtual SubmissionCollection GetQueryResult(SubmissionQuery query, Int32 page, Int32 pageSize)
        {
            return ContestHandler.GetQueryResult(query, page, pageSize);
        }

        public virtual SubmissionCollection GetQueryResult(SubmissionQuery query, Int32 page, Int32 pageSize, out Int32 totalItems)
        {
            return ContestHandler.GetQueryResult(query, page, pageSize, out totalItems);
        }

        #endregion

        public virtual void OnContestAdded(String sender, EPiServerCommonEventArgs e)
        {
            if (ContestAdded != null)
                ContestAdded(sender, e);
        }

        public virtual void OnContestUpdated(String sender, EPiServerCommonEventArgs e)
        {
            if (ContestUpdated != null)
                ContestUpdated(sender, e);
        }

        public virtual void OnContestRemoved(String sender, EPiServerCommonEventArgs e)
        {
            if (ContestRemoved != null)
                ContestRemoved(sender, e);
        }

        public virtual void OnQuestionAdded(String sender, EPiServerCommonEventArgs e)
        {
            if (QuestionAdded != null)
                QuestionAdded(sender, e);
        }

        public virtual void OnQuestionUpdated(String sender, EPiServerCommonEventArgs e)
        {
            if (QuestionUpdated != null)
                QuestionUpdated(sender, e);
        }

        public virtual void OnQuestionRemoved(String sender, EPiServerCommonEventArgs e)
        {
            if (QuestionRemoved != null)
                QuestionRemoved(sender, e);
        }

        public virtual void OnAlternativeAdded(String sender, EPiServerCommonEventArgs e)
        {
            if (AlternativeAdded != null)
                AlternativeAdded(sender, e);
        }

        public virtual void OnAlternativeUpdated(String sender, EPiServerCommonEventArgs e)
        {
            if (AlternativeUpdated != null)
                AlternativeUpdated(sender, e);
        }

        public virtual void OnAlternativeRemoved(String sender, EPiServerCommonEventArgs e)
        {
            if (AlternativeRemoved != null)
                AlternativeRemoved(sender, e);
        }

        public virtual void OnAnswerAdded(String sender, EPiServerCommonEventArgs e)
        {
            if (AnswerAdded != null)
                AnswerAdded(sender, e);
        }

        public virtual void OnSubmissionAdded(String sender, EPiServerCommonEventArgs e)
        {
            if (SubmissionAdded != null)
                SubmissionAdded(sender, e);
        }

        public virtual void OnSubmissionRemoved(String sender, EPiServerCommonEventArgs e)
        {
            if (SubmissionRemoved != null)
                SubmissionRemoved(sender, e);
        }

        public virtual void OnWinnerAdded(String sender, EPiServerCommonEventArgs e)
        {
            if (WinnerAdded != null)
                WinnerAdded(sender, e);
        }

        public virtual void OnWinnerRemoved(String sender, EPiServerCommonEventArgs e)
        {
            if (WinnerRemoved != null)
                WinnerRemoved(sender, e);
        }
    }
}